<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<%
	String path = request.getContextPath();
%>
<html>
	<head>
		<title>模板维护</title>
<link rel="stylesheet" type="text/css"
	href="<%=path%>/css/btn_class.css" />
<link rel="stylesheet" type="text/css"
	href="<%=path%>/ext-3.2.0/resources/css/ext-all.css" />

	<script type="text/javascript" src="<%=path%>/ext-3.2.0/adapter/ext/ext-base.js"></script>
    <script type="text/javascript" src="<%=path%>/ext-3.2.0/ext-all.js"></script>
    	<script type="text/javascript" src="<%=path%>/js/datepicker/WdatePicker.js" defer="defer"></script>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	
</head>

<body >
<script type="text/javascript">
Ext.BLANK_IMAGE_URL = "<%=path%>/ext-3.2.0/resources/images/default/s.gif";
Ext.onReady(function(){
	
	var Jthtwb_mould = Ext.data.Record.create([ {
		name : 'fid',
		mapping : 'fid',
		type : 'string'
	}, {
		name : 'f1',
		mapping : 'f1',
		type : 'string'
	}, {
		name : 'f2',
		mapping : 'f2',
		type : 'string'
	}, {
		name : 'f3',
		mapping : 'f3',
		type : 'string'
	}, {
		name : 'f4',
		mapping : 'f4',
		type : 'string'
	}, {
		name : 'f5',
		mapping : 'f5',
		type : 'string'
	}, {
		name : 'fopdate',
		mapping : 'fopdate',
		type : 'string'
	}]);

	var ds_mould = new Ext.data.Store({
		reader : new Ext.data.JsonReader({
			totalProperty : 'totalProperty',
			root : 'root'
		}, Jthtwb_mould),
		idProperty : 'threadid',
		remoteSort : true,
		url : 'reportInfo!queryReportDataExcel.do'
	});

	ds_mould.load({
		params : {
			start : 0,
			limit : 30
		}
	});


	//定义勾选框，不需要可不必定义
	var sm_mould = new Ext.grid.CheckboxSelectionModel({
		singleSelect : true
	});

	//定义列
	var colM_mould = new Ext.grid.ColumnModel([ sm_mould, new Ext.grid.RowNumberer(),//增加自动编号，不需要可不必定义
	    {
			header : '指标名称',
			dataIndex : 'f2',
			width : 200,
			renderer : function(value) {
				if (value == "null") {
					return "";
				} else {
					return value;
				}
			}
		},{
			header : '科室',
			dataIndex : 'f1',
			width : 150,
			renderer : function(value) {
				if (value == "null") {
					return "";
				} else {
					return value;
				}
			}
		},{
			header : '指标值',
			dataIndex : 'f3',
			width : 120,
			renderer : function(value) {
				if (value == "null") {
					return "";
				} else {
					return value;
				}
			}
		},{
			header : '上传时间',
			dataIndex : 'fopdate',
			width : 120,
			renderer : function(value) {
				if (value == "null") {
					return "";
				} else {
					return value;
				}
			}
		} ]);

	//生成表格
	var grid_mould = new Ext.grid.GridPanel({
		closable : false,
		region : 'center',
		height : 350,
		autoWidth : true,
		cm : colM_mould,
		ds : ds_mould,
		sm : sm_mould,
		enableHdMenu : false
	});
	
	
	var btn_add = new Ext.Button({
		text : '新增',
		iconCls : 'sy-add',
		handler : function() {
			mould_detail_form();
		}
	});

	var btn_upload_file = new Ext.Button({
		text : '上传文件',
		iconCls : 'sy-page_white_add',
		handler : function() {
			//var record = grid_mould.getSelectionModel().getSelected();
			file_import_fun("");
		}
	});
	
	
	function file_import_fun(fbh_mould) {
		
		
		
		var fileform = new Ext.FormPanel({
            region : 'center',
            labelWidth : 65,
            labelAlign: 'right',
            frame : true,
            bodyStyle : 'padding:5px 5px 0',
            autoScroll : true,
            border : false,
            fileUpload : true,
            items : [ new Ext.form.TextField({
						fieldLabel : '数据月度',
						format: 'yyyy-MM-dd',
						id:'fdate_id',
						name:'fdate_data',
						width : 140,
						allowBlank : false,
						//style:"cursor:pointer;color:red",
						listeners : {
							'focus' : function() {
								WdatePicker({startDate:'%y-%M-%d',dateFmt:'yyyy-MM-dd',alwaysUseStartDate:true});
							}
						}
					}) , {
                        xtype : 'textfield',
                        fieldLabel : '选择文件',
                        id : 'upload2',
                        name : 'upload', 
                        inputType : 'file',
                        allowBlank : false,
                        height : 22,
                        anchor : '98%'
                    }],
            buttons : [{
                text : '确定',
                type : 'submit',
                iconCls : 'sy-sure',
                handler : function() {
                	
                    //遮罩
					var myMask = new Ext.LoadMask(Ext.getBody(), {msg:"Please wait..."});  
					//myMask.show();  
                    if (!fileform.form.isValid()) {return;}
                    fileform.form.submit({
                        waitMsg : '正在导入...',
                        url : 'reportInfo!importReportDataExcel.do',
                        params:{
		    	        	"fbh" : fbh_mould
			    	    },
                        success : function(form, action) {
                            //myMask.hide();
                            file_import_window.close();
                            Ext.Msg.alert('', '导入成功!');
                            ds_mould.reload();
                        },
                        failure : function(form, action) {
                            myMask.hide();
                            if (action.failureType == Ext.form.Action.SERVER_INVALID)
                                Ext.MessageBox.alert('警告',
                                        action.result.errors.msg);
                        }
                    });
                }
            }, {
                text : '关闭',
                type : 'submit',
                iconCls : 'sy-cancel',
                handler : function() {
                    file_import_window.close(this);
                }
            }]
        });

		var file_import_window = new Ext.Window({
			width : 400,
			height : 130,
			title : '导入数据信息',
			iconCls : 'sy-win-flag',
			modal : true,
			items : [ fileform ]
		});
		file_import_window.show();
	
	}
	
	function mould_detail_form() {
		
		var mould_form_send = new Ext.form.FormPanel({  
	        frame : true,  
			labelWidth : 55,
	        waitMsgTarget: true,  
	        items : [{
				xtype : 'textfield',
				fieldLabel : '模板名称',
				id : 'fname_id',
				name : 'fname',
				allowBlank : false,
				width : 200
			},{
				xtype : 'textarea',
				fieldLabel : '备注',
				id : 'fdesc_id',
				name : 'fdesc',
				height : 60,
				width : 240
			}]});
			
		var btn_save_form = new Ext.Button({
			text : '保存',
			iconCls : 'sy-save',
			handler : function(btn) {
				var frm = mould_form_send.getForm();
				
				if (frm.isValid()) {
					frm.submit({
					    url : 'mouldInfo!saveMouldInfo.do',
					    method : 'POST',
						waitTitle : '请稍候',
						waitMsg : '正在提交表单数据,请稍候...',
						success : function(form, action) {
								ds_mould.reload();
								mould_detail_window.close();
						},
						failure : function(form, action) {
							
						},// failure
						icon : Ext.Msg.ERROR
					});
				};// isValid
			}
		});
		
		var btn_reset_form = new Ext.Button({
			text : '取消',
			iconCls : 'sy-reset',
			handler : function(btn) {
				mould_detail_window.close();
			}

		});

		var mould_detail_window = new Ext.Window({
			tbar : [ btn_save_form, '-', btn_reset_form],
			width : 340,
			height : 200,
			title : '模板管理',
			iconCls : 'sy-win-flag',
			modal : true,
			items : [ mould_form_send ]
		});
		mould_detail_window.show();
	} // end form

	var btn_delete = new Ext.Button({
		text : '删除',
		iconCls : 'sy-delete',
		handler : function() {
			var record = grid_user.getSelectionModel().getSelected();
			if (record) {
				Ext.Msg.confirm('确认删除', '删除操作将会导致被授权该角色的用户无法正常使用系统，您确定删除吗？', function(btn) {
					if (btn == 'yes') {
						Ext.Ajax.request({
							url : 'mould!deleteMouldInfo.do',
							params:{
			    	        	"fbh" : record.data.fbh
				    	    },
							success : function() {
								ds_mould.removeAll();
								ds_mould.reload();
								Ext.MessageBox.alert('提示', '删除成功！');
							},
							failure : function() {
								Ext.Msg.show({
									title : '错误提示',
									msg : '删除记录失败！',
									buttons : Ext.Msg.OK,
									icon : Ext.Msg.ERROR
								});
							}
						});
					}
				});
			} else {
				Ext.MessageBox.alert('提示', '请选择一行纪录进行操作！');
				return;
			}
		}
	});
	
	var btn_refresh = new Ext.Button({
		text : '刷新',
		iconCls : 'sy-refresh',
		handler : function() {
			ds_mould.removeAll();
			ds_mould.reload();
		}
	});
	
    var panel = new Ext.Panel({
    	region: "center",
		layout:'fit',
		border : true,
	    //title:'&nbsp;&nbsp;&nbsp;图表示例',
	    //collapsible : true,
		margins:'0 5 0 0',
		tbar : [ btn_delete, '-', btn_upload_file],
		items : [ grid_mould]
	});
    
 	new Ext.Viewport( {
		layout : "border",
		items : [panel]
	});
});
</script>

</body>
</html>
